//
//  ViewController.m
//  弹性动画
//
//  Created by 裴波波 on 16/4/24.
//  Copyright © 2016年 裴波波. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIImageView *testView;

@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    _testView = [[UIImageView alloc] init];
    _testView.frame = CGRectMake(0, 100, 100, 100);
    _testView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:_testView];
    
    UIButton * btn = [[UIButton alloc] init];
    btn.frame = CGRectMake(50, 200, 80, 40);
    btn.backgroundColor = [UIColor redColor];
    [btn setTitle:@"弹弹弹" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}

-(void)clickBtn{

    
    
    /*
     //Duration 动画持续时间
     //animations  动画过程
     [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>];
     
     //block里是动画完成的回调
     [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>];
     
     //delay 等待时间
     //options 动画类型
     [UIView animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:<#(UIViewAnimationOptions)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>];
     
     //弹性动画
     //damping:阻尼，范围0-1，阻尼越接近于0，弹性效果越明显
     //velocity:弹性复位的速度
     [UIView animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> usingSpringWithDamping:<#(CGFloat)#> initialSpringVelocity:<#(CGFloat)#> options:<#(UIViewAnimationOptions)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>];
     
     //关键帧动画
     [UIView animateKeyframesWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:<#(UIViewKeyframeAnimationOptions)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>];
     */

    
    
    
    
    

    //左右
//    [_testView.layer setValue:@(0) forKeyPath:@"transform.translation.x"];
//    [UIView animateWithDuration:.6 delay:0 usingSpringWithDamping:.3 initialSpringVelocity:.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
//        
//        [_testView.layer setValue:@(150) forKeyPath:@"transform.translation.x"];
//    } completion:^(BOOL finished) {
//        
//    }];
    
    
    //缩放
    [_testView.layer setValue:@(2.0) forKeyPath:@"transform.scale"];
    [UIView animateWithDuration:.6 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:.5 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
        [_testView.layer setValue:@(1.0) forKeyPath:@"transform.scale"];
    } completion:^(BOOL finished) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
